import http from "@/api";
<#if genPage>
import { ReqPage, ResPage } from "@/api/interface";
</#if>

const baseUrl: string = "/${moduleName}/${controller.url}";
<#if genPage>

export interface ${pageParam.className} extends ReqPage {
  <#list fieldInfoList as field>
  <#if field.showInQuery>
  <#if field.comment!?length gt 0>
  // ${field.comment}<#if field.enumDict??> 参考字典: ${field.enumDict.name}</#if>
  <#elseif field.enumDict??>
  // 参考字典: ${field.enumDict.name}
  </#if>
  ${field.fieldName}?: ${field.tsFieldType};
  </#if>
  </#list>
}

export interface ${pageResult.className} {
  <#list fieldInfoList as field>
  <#if field.showInList>
  <#if field.comment!?length gt 0>
  // ${field.comment}<#if field.enumDict??> 参考字典: ${field.enumDict.name}</#if>
  <#elseif field.enumDict??>
  // 参考字典: ${field.enumDict.name}
  </#if>
  ${field.fieldName}: ${field.tsFieldType};
  </#if>
  </#list>
}

export const get${entity.className}Page = (param: ${pageParam.className}) => {
  return http.get<ResPage<${pageResult.className}>>(baseUrl + `/page`, param);
};
</#if>
<#if genInfo>

export interface ${infoResult.className} {
  <#list fieldInfoList as field>
  <#if field.showInInfo>
  <#if field.comment!?length gt 0>
  // ${field.comment}<#if field.enumDict??> 参考字典: ${field.enumDict.name}</#if>
  <#elseif field.enumDict??>
  // 参考字典: ${field.enumDict.name}
  </#if>
  ${field.fieldName}: ${field.tsFieldType};
  </#if>
  </#list>
}

export const get${entity.className}Info = (id: string) => {
  return http.get<${infoResult.className}>(baseUrl + `/info/` + id);
};
</#if>
<#if genSave>

export interface ${saveParam.className} {
  <#list fieldInfoList as field>
  <#if field.showInSave>
  <#if field.comment!?length gt 0>
  // ${field.comment}<#if field.enumDict??> 参考字典: ${field.enumDict.name}</#if>
  <#elseif field.enumDict??>
  // 参考字典: ${field.enumDict.name}
  </#if>
  ${field.fieldName}<#if !field.required>?</#if>: ${field.tsFieldType};
  </#if>
  </#list>
}

export const save${entity.className} = (param: ${saveParam.className}) => {
  return http.post(baseUrl + `/save`, param);
};
</#if>
<#if genUpdate>

export interface ${updateParam.className} {
  <#list fieldInfoList as field>
  <#if field.showInUpdate>
  <#if field.comment!?length gt 0>
  // ${field.comment}<#if field.enumDict??> 参考字典: ${field.enumDict.name}</#if>
  <#elseif field.enumDict??>
  // 参考字典: ${field.enumDict.name}
  </#if>
  ${field.fieldName}<#if !field.required>?</#if>: ${field.tsFieldType};
  </#if>
  </#list>
}

export const update${entity.className} = (param: ${updateParam.className}) => {
  return http.post(baseUrl + `/update`, param);
};
</#if>
<#if genDeleted>

export const delete${entity.className} = (ids: string[]) => {
  return http.post(baseUrl + `/delete`, ids);
};
</#if>
<#if genImport>

export const get${entity.className}ImportTemplate = () => {
  return http.get<any>(baseUrl + `/import/template`, {}, { loading: true, responseType: "blob" });
};

export const import${entity.className}Excel = (params: FormData) => {
  return http.post(baseUrl + `/import/excel`, params, { cancel: false });
};
</#if>
<#if genExport>

export const export${entity.className}Excel = (param: ${pageParam.className}) => {
  return http.get<any>(baseUrl + `/export/excel`, param, { loading: true, responseType: "blob" });
};
</#if>